#! /bin/sh

PATH="`pwd`/../bin:$PATH"
export PATH

if test -z "$MAKE"
  then
    gmake=`which gmake`

    if test $? = 0 
      then
        MAKE=gmake
      else
        MAKE=make
      fi
  fi

svn=`which svn`

if test -z "$svn"
  then
    echo "error: can't find svn, tests will not work!" 1>&2
    exit 77 
  fi

svnadmin=`which svnadmin`

if test -z "$svnadmin"
  then
    echo "error: can't find svnadmin, tests will not work!" 1>&2
    exit 77
  fi

(
set -x
rm -rf svntmp
svnadmin create svntmp
test -h share || ln -sf .. share || exit 1
rm -rf tmp 
FW_ROOT="`pwd`"
export FW_ROOT
fw-init --name tmp                                              \
        --revision svn                                          \
        --svn_project_path "file://`pwd`/svntmp/tmp/trunk"      \
        --svn_tag_root "file://`pwd`/svntmp/tmp/tags"           \
        --template script --trace     || exit 1
cd tmp
( svn status | grep '^?' ) && exit 1
./bootstrap || exit 1
( svn status | grep '^?' ) && exit 1
./build || exit 1
"$MAKE" -s check || exit 1
( svn status | grep '^?' ) && exit 1
"$MAKE" -s maintainer-clean
( svn status | grep '^?' ) && exit 1
test -z "`find . -name '*.am'`" || exit 1
) > test-svn.out 2>&1 || exit 1

rm -rf tmp || exit 1
rm share || exit 1
rm -rf svntmp || exit 1
